﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLNhaThuoc.DTO;

namespace QLNhaThuoc.MyClass
{
    abstract class CTPhieuHelper
    {
        public DataGridView DataSource { get; set; }
        //public int MaPhieu { get; set; }

        public int ThanhTien
        {
            get { return _thanhTien; }
        }

        private int _thanhTien;
        
        public virtual CTPhieu[] TaoDanhSachChiTiet()
        {
            int n = DataSource.Rows.Count - 1;
            CTPhieu[] ctPhieu = new CTPhieu[n];

            for (int i = 0; i < n; i++)
            {
                ctPhieu[i] = new CTPhieu();
                //ctPhieu[i].Ma = MaPhieu;
                string maThuoc = ctPhieu[i].MaThuoc = DataSource.Rows[i].Cells["MaThuoc"].Value.ToString();
                int soLuong = ctPhieu[i].SoLuong = int.Parse(DataSource.Rows[i].Cells["SoLuong"].Value.ToString());
                ctPhieu[i].ThanhTien = int.Parse(DataSource.Rows[i].Cells["ThanhTien"].Value.ToString());
                _thanhTien += ctPhieu[i].ThanhTien;
                CapNhatSoLuongThuoc(maThuoc, soLuong);
            }

            return ctPhieu;
        }

        protected abstract void CapNhatSoLuongThuoc(string maThuoc, int soLuong);
    }
}
